package utils

import (
	"github.com/globalsign/mgo"
)

var (
	session interface{}
)

func GetCollection(db string) *mgo.Collection {
	if session == nil {
		session, _ = mgo.Dial("127.0.0.1:27017")
	}

	collection, err := Get("collection." + db)
	if err == nil {
		return collection.(*mgo.Collection)
	} else {
		// 对应的 collection 不存在
		collection = session.(*mgo.Session).DB(db).C("logger")

		Set("collection." + db, collection)

		return collection.(*mgo.Collection)
	}
}

